//面试常考！
package main

import "fmt"

type ListNode struct {
	Val int
	Next *ListNode
}

func reverseList(head *ListNode) *ListNode {
	var prev *ListNode
	curr := head
	for curr != nil {
		next := curr.Next
		curr.Next = prev
		prev = curr
		curr = next
	}
	return prev
}



func main() {
	// 读取用户输入的链表
	var n int
	fmt.Scan(&n)
	head := &ListNode{}
	node := head
	for i := 0; i < n; i++ {
		var val int
		fmt.Scan(&val)
		node.Next = &ListNode{Val: val}
		node = node.Next
	}

	// 反转链表
	head = reverseList(head.Next)

	// 输出反转后的链表
	node = head
	for node != nil {
		fmt.Printf("%d ", node.Val)
		node = node.Next
	}
}
